package servlet;

import javabean.User;
import service.AccountService;
import service.AccountServiceImpl;
import service.UserService;
import service.UserServiceImpl;
import servlet.BaseServlet.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/accountservlet")
public class AccountServlet extends BaseServlet {
    UserService userService=new UserServiceImpl();
    AccountService accountService = new AccountServiceImpl();

    public void web_member_manager_show(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String id =req.getParameter("id");
    req.setAttribute("user",userService.queryUserById(Integer.parseInt(id)));
    req.setAttribute("account",accountService.showAccountByAccountId(Integer.parseInt(id)));
    req.getRequestDispatcher("/pc/web_member_manager_show.jsp").forward(req,resp);
    }


    public void deleteAccount(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String accountId = req.getParameter("accountId");
        accountService.deleteAccountByAccountId(Integer.parseInt(accountId));
        userService.deleteUserById(Integer.parseInt(accountId));
        resp.sendRedirect(req.getContextPath()+"/userservlet?action=pc_queryuserlistbyrole&role=0");

    }
}
